package com.chinameyer.workorders.utils;

import java.util.Random;

/**
 * @Author meyer@HongYe
 */
public class RandomStringUtil {

    public static final String SOURCES = "ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnpqrstuvwxyz123456789";

    public static final String NUMBER_SOURCES = "1234567890";


    /**
     * 生成某一长度的随机字符串
     * @param random
     * @param characters
     * @param length
     * @return
     */
    public static String generateString(Random random, String characters, int length) {
        char[] text = new char[length];
        for (int i = 0; i < length; i++) {
            text[i] = characters.charAt(random.nextInt(characters.length()));
        }
        return new String(text);
    }

    public static String generateNumberString(Random random, String characters, int length) {
        char[] text = new char[length];
        for (int i = 0; i < length; i++) {
            text[i] = characters.charAt(random.nextInt(characters.length()));
        }
        return new String(text);
    }

    public static void main(String[] args) {
        System.out.println(generateString(new Random(), SOURCES, 4));
    }
}
